var e = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/typeof")), t = require("utils/core.js"), a = requirePlugin("live-player-plugin");

App({
    onShow: function(o) {
        var i = this;
        console.log(o, "888888", (0, e.default)(a)), 1007 != o.scene && 1008 != o.scene && 1044 != o.scene || void 0 !== a && a.getShareParams().then(function(t) {

            var a = i.getCache("usermid");
            if ("object" != (0, e.default)(a)) {
                var o = {};
                o.mid = t.custom_params, console.log(o, "77777777777777777"), i.url(o), i.setCache("usermid", o), 
                console.log(t.custom_params, "6666666"), wx.setStorageSync("livemid", t.custom_params);
            }
            "object" == (0, e.default)(a) && (a.mid = t.custom_params, console.log(a, "77777777777777777"), 
            i.url(a), i.setCache("usermid", a), console.log(t.custom_params, "6666666"), wx.setStorageSync("livemid", t.custom_params));
        }).catch(function(e) {
            console.log("get share params", e);
        });
        var n = this;
        this.onLaunch();
        try {
            "" != this.getCache("userinfo_id") && t.get("member", {}, function(e) {
                n.setCache("userinfo_id", e.id);
            });
        } catch (e) {}
    },
    onLaunch: function() {
        var e = this;
        wx.getSystemInfo({
            success: function(t) {
                "0" == t.model.indexOf("iPhone X") ? e.setCache("isIpx", t.model) : e.setCache("isIpx", "");
            }
        });
        var t = this;
        wx.getSystemInfo({
            success: function(e) {
                wx.setStorageSync("systemInfo", e);
                var a = e.windowWidth, o = e.windowHeight;
                t.globalData.ww = a, t.globalData.hh = o;
            }
        }), setTimeout(function() {
            t.scanCarts();
        }, 50), setInterval(function() {
            if (t.getCache("userinfo_openid")) {
                // var e = wx.getStorageSync("goodnum");
                // // console.log(t.globalData.tabnum, "tabnum");
                // var a = t.globalData.tabnum;
                // 0 != e && "" != a ? wx.setTabBarBadge({
                //     index: a,
                //     text: "" + e
                // }) : wx.removeTabBarBadge({
                //     index: a
                // });
            }
        }, 250);
    },
    scanCarts: function() {
        t.get("member/cart/get_cart", {}, function(e) {
            if (e.total) {
                if (0 != e.total) {
                    var t = e.total;
                    wx.setStorageSync("goodnum", t);
                }
            } else if (null != e.merch_list) {
                t = 0;
                for (var a = e.merch_list, o = 0; o < a.length; o++) {
                    for (var i = a[o].list, n = 0; n < i.length; n++) t += parseInt(i[n].total);
                    wx.setStorageSync("goodnum", t);
                }
            } else wx.setStorageSync("goodnum", 0);
        });
    },
    checkAuth: function(e) {
        var a = "/pages/auth/index", o = getCurrentPages(), i = o[o.length - 1];
        if (console.log(i), "pages/auth/index" == i.route || "/pages/auth/index" == i.route) return !0;
        var n = {
            params: i.options || null,
            url: i.route
        };
        if (n.params.hasOwnProperty("scene")) {
            var r = {}, s = decodeURIComponent(n.params.scene).split("&").shift().split("=");
            r.id = s[1], n.params = r;
        }
        this.setCache("routeData", n);
        this.getCache("userinfo");
        wx.getSetting({
            success: function(o) {
                o.authSetting["scope.userInfo"] ? (t.get("member", {}, function(e) {
                    e.error && wx.navigateTo({
                        url: a
                    });
                }), e && e()) : wx.navigateTo({
                    url: a
                });
            }
        });
    },
    requirejs: function(e) {
        return require("utils/" + e + ".js");
    },
    getConfig: function() {
        if (null !== this.globalData.api) return {
            api: this.globalData.api,
            approot: this.globalData.approot,
            appid: this.globalData.appid
        };
        var e = wx.getExtConfigSync();
        return this.globalData.api = e.config.api, this.globalData.approot = e.config.approot, 
        this.globalData.appid = e.config.appid, e.config;
    },
    getCache: function(e, t) {
        var a = +new Date() / 1e3, o = "";
        a = parseInt(a);
        try {
            (o = wx.getStorageSync(e + this.globalData.appid)).expire > a || 0 == o.expire ? o = o.value : (o = "", 
            this.removeCache(e));
        } catch (e) {
            o = void 0 === t ? "" : t;
        }
        return o = o || "";
    },
    setCache: function(e, t, a) {
        var o = +new Date() / 1e3, i = !0, n = {
            expire: a ? o + parseInt(a) : 0,
            value: t
        };
        try {
            wx.setStorageSync(e + this.globalData.appid, n);
        } catch (e) {
            i = !1;
        }
        return i;
    },
    removeCache: function(e) {
        var t = !0;
        try {
            wx.removeStorageSync(e + this.globalData.appid);
        } catch (e) {
            t = !1;
        }
        return t;
    },
    close: function() {
        this.globalDataClose.flag = !0, wx.reLaunch({
            url: "/pages/index/index"
        });
    },
    getSet: function() {
        var e = this;
        "" == e.getCache("cacheset") && setTimeout(function() {
            var a = e.getCache("cacheset");
            t.get("cacheset", {
                version: a.version
            }, function(t) {
                t.update && e.setCache("cacheset", t.data);
            });
        }, 10);
    },
    url: function(e) {
        e = e || {};
        var t, a, o = {}, i = this.getCache("usermid");
        for (var n in t = e.mid || "", a = e.merchid || "", i) void 0 !== i[n] && (o[n] = i[n]);
        "" != i ? ("" != i.mid && void 0 !== i.mid || (o.mid = t), "" != i.merchid && void 0 !== i.merchid || (o.merchid = a)) : (o.mid = t, 
        o.merchid = a), this.setCache("usermid", o);
    },
    impower: function(e, t, a) {
        wx.getSetting({
            success: function(o) {
                o.authSetting["scope." + e] || wx.showModal({
                    title: "用户未授权",
                    content: "您点击了拒绝授权，暂时无法" + t + "，点击去设置可重新获取授权喔~",
                    confirmText: "去设置",
                    success: function(e) {
                        e.confirm ? wx.openSetting({
                            success: function(e) {}
                        }) : "route" == a ? wx.switchTab({
                            url: "/pages/index/index"
                        }) : "details" == a || wx.navigateTo({
                            url: "/pages/index/index"
                        });
                    }
                });
            }
        });
    },
    globalDataClose: {
        flag: !1
    },
    globalData: {
      appid: "wx6fd40977aa7b9b42",//wx4d5d2f767ee91a16   wx9431d03e1d1dd89f   wx6fd40977aa7b9b42
      api: "https://ydjk.people.cn/app/ewei_shopv2_api.php?i=2",//ydjk.people.cn/app/ewei_shopv2_api.php?i=2
      approot: "https://ydjk.people.cn/addons/ewei_shopv2/",
          userInfo: null
    }
});